//
//  WhoamIAccount.m
//  ALittleReminder
//
//  Created by Kevin Basanti on 11-11-23.
//  Copyright (c) 2011 __MyCompanyName__. All rights reserved.
//

#import "WhoamIAccount.h"

@implementation WhoamIAccount



-(IBAction)goAway:(id)sender{
    [sender resignFirstResponder];
    
}


-(IBAction)onClickClose:(id)sender{
    
    
    [self dismissModalViewControllerAnimated:YES];
    
}

-(IBAction)onClickCreate:(id)sender{
    if([password.text isEqualToString:repassword.text]){
        
        NSString *nameText = name.text;
        NSString *addressText = address.text;
        NSString *cityText = city.text;
        NSString *phoneText = phone.text;
        NSString *passwordText = password.text;
        NSString *medicalText = medical.text;
        
        
        
        if([ phoneText length] == 10){
            
            
            
            NSString *infoText=[nameText stringByAppendingFormat:@"-%@-%@-%@-%@-%@",addressText,cityText,phoneText,medicalText,passwordText];
            NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
            NSString *docDir = [paths objectAtIndex: 0];
            NSString *docFile = [docDir stringByAppendingPathComponent: @"myInfo.txt"];
            
            //your variable "deck"
            
            
            NSError *error;
            if ([infoText writeToFile:docFile atomically:YES encoding:NSStringEncodingConversionAllowLossy error:&  error]
                ) {
                NSLog(@"saved");
            }else{
                NSLog(@"not saved: %@",error);
            }
            
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Account Created" message:nil delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
            [alert show];
            
            
        }
        else{
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Invalid Phone Number" message:nil delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
            [alert show];
        }
        
    }
    else{
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Password Does Not Match" message:nil delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
        [alert show];
    }
    
    
}

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{   
    [scroller setScrollEnabled:YES];
    [scroller setContentSize:CGSizeMake(320, 1000)];
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
}

- (void)viewDidUnload


{
    
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

@end
